<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>预警规则管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var roleId="";
		 $(function(){
			 roleId = '${warningRole.id}';
			$.ajax({
	            type:"POST",
	            url:'${ctx}/guobo/rw/treeGroupData?rwIds='+'${warningRole.rwIds}',
	            //返回数据的格式
	            datatype: "json",
	            success:function(data){
	            	var selects = new treeSelect();
	    			selects.bind($("#mul_test"), data.datas);
	            },
	            //调用出错执行的函数
	            error: function(){
	            	$.jBox.alert('获取失败!', '提示!');
	            }
	         });
			
		}); 
	
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#btn_add").click(function(){
				var warningRoleId = $("#warningRoleId").val();
				if(warningRoleId==null || warningRoleId=='null' || warningRoleId=='' || warningRoleId=='undefined'){
					alert('请先保存!');
					return;
				}
				/* var iWidth=600; //窗口宽度 
				var iHeight=560;//窗口高度 
				var iTop=(window.screen.height-iHeight)/2; 
				var iLeft=(window.screen.width-iWidth)/2;				
				window.showModalDialog('${ctx}/guobo/asset/findRfidsNotInRole?warningRoleId='+warningRoleId,'RFID信息',"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no"); 
				 */
				var url='${ctx}/guobo/asset/findRfidsNotInRole?warningRoleId='+warningRoleId;
				var name='请选择RFID';
				var iWidth=720;                          //弹出窗口的宽度; 
		        var iHeight=600;                         //弹出窗口的高度; 
		        //获得窗口的垂直位置 
		        var iTop = (window.screen.availHeight - 30 - iHeight) / 2; 
		        //获得窗口的水平位置 
		        var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; 
				window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no'); 
			});
			
			$("#btnSubmit").click(function(){
				$.ajax({
	                cache: true,
	                type: "POST",
	                url:'${ctx}/guobo/warningRole/saveWarningRole',
	                data:$('#inputForm').serialize(),// 你的formid
	                async: false,
	                error: function(request) {
	                    alert("保存失败");
	                },
	                success: function(data) {
	                	var result = data.code;
						var warningRoleId = data.id;
						alert('保存成功!');
	                	$("#warningRoleId").val(warningRoleId);
	                	$("#btnSubmit").attr("disabled", true); 
	                }
	            });
			});
		});
		
		function deleteWR(wrid){
			alert(roleId);
			if(confirm("确定要删除rfid信息吗?")){
				$.ajax({
		            type:"POST",
		            url:'${ctx}/guobo/warnroleRfid/deleteWarningRoleRfid',
		            data:{rfid:wrid},
		            //返回数据的格式
		            datatype: "json",
		            success:function(data){
		            	$.jBox.alert('保存成功!', '提示!');
		            	location.reload();
		            },
		            //调用出错执行的函数
		            error: function(){
		            	$.jBox.alert('保存失败!', '提示!');
		            }         
		         });
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/guobo/warningRole/">预警规则列表</a></li>
		<li class="active"><a href="${ctx}/guobo/warningRole/form?id=${warningRole.id}">预警规则<shiro:hasPermission name="guobo:warningRole:edit">${not empty warningRole.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="guobo:warningRole:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="warningRole" action="${ctx}/guobo/warningRole/saveWarningRole" method="post" class="form-horizontal">
		<form:hidden path="id" id="warningRoleId"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">规则名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">读写器：</label>
			<div class="controls">
				<form:input path="rwNames" id="mul_test" htmlEscape="false" class="input-xlarge "/>
				<form:input path="rwIds" htmlEscape="false" type="hidden" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">状态：</label>
			<div class="controls">
				<form:select path="status" class="input-xlarge">
					<form:option value="" label="请选择"/>
					<form:options items="${fns:getDictList('warningrole_status')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">规则开始日期：</label>
			<div class="controls">
				<input name="startdate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${warningRole.startdate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">规则结束日期：</label>
			<div class="controls">
				<input name="enddate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${warningRole.enddate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="guobo:warningRole:edit"><input id="btnSubmit" class="btn btn-primary" type="button" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
		<div id="toolbar" class="btn-group">
			<input id="btn_add" class="btn btn-primary" type="button" value="新 增"/>
		</div>
		<iframe src="${ctx}/guobo/warningRole/findListByWarnroleId?id=${warningRole.id}" frameborder="0" scrolling="yes" height="100%" width="100%" noresize="noresize">
			
		</iframe>
		<%-- <div id="toolbar" class="btn-group">
			<input id="btn_add" class="btn btn-primary" type="button" value="新 增"/>
		</div>
		<table id="contentTable" class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>序号</th>
					<th>RFID</th>
					<th>资产名称</th>
					<shiro:hasPermission name="guobo:warningRole:edit"><th>操作</th></shiro:hasPermission>
				</tr>
			</thead>
				<c:forEach items="${roleRfids}" var="roleRfid" varStatus="vs">
					<tr>
						<td>${vs.index+1}</td>
						<td>${roleRfid.rfid}</td>
						<td>${roleRfid.asset.name}</td>
						<shiro:hasPermission name="guobo:warnroleRfid:edit"><td>
							<input id="btnSubmit" class="btn btn-primary" type="button" value="删 除" onclick="deleteWR('${roleRfid.id}')"/>
						</td></shiro:hasPermission>
					</tr>
				</c:forEach>
				
			<tbody>
			</tbody>
		</table>		 --%>
				
	</form:form>
</body>
</html>